package org.zuel.huhuForum.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitmqConfig {
    public static final String DISCUSS_SEARCH_EXCHANGE="EDiscussSearch";

    public static final String SEARCH_ADD_EXCHANGE="ESearchADD";

    public static final String QUEUE_DISCUSS_AD="QDiscussAd";

    public static final String QUEUE_DISCUSS_COUNT="QDiscussCount";

    public static final String QUEUE_COMMENT_AD="QComment";

    public static final String QUEUE_SEARCH_AD="QSearch";

    public static final String QUEUE_MESSAGE="QMessage";

    public static final String QUEUE_EMAIL="QEmail";

    public static final String QUEUE_HISTORY="QHistory";

    public static final String QUEUE_READED="QReaded";

    @Bean("EDiscussSearch")
    public DirectExchange EDiscussSearch(){
        return new DirectExchange(DISCUSS_SEARCH_EXCHANGE);
    }

    @Bean("ESearchADD")
    public DirectExchange ESearchADD(){
        return new DirectExchange(SEARCH_ADD_EXCHANGE);
    }

    @Bean("QDiscussAd")
    public Queue QDiscussAd(){

        return QueueBuilder.durable(QUEUE_DISCUSS_AD).build();
    }

    @Bean("QDiscussCount")
    public Queue QDiscussCount(){
        return QueueBuilder.durable(QUEUE_DISCUSS_COUNT).build();
    }

    @Bean("QComment")
    public Queue QComment(){

        return QueueBuilder.durable(QUEUE_COMMENT_AD).build();
    }

    @Bean("QSearch")
    public Queue QSearch(){
        return QueueBuilder.durable(QUEUE_SEARCH_AD).build();
    }

    @Bean("QMessage")
    public Queue QMessage(){

        return QueueBuilder.durable(QUEUE_MESSAGE).build();
    }

    @Bean("QEmail")
    public Queue QEmail(){

        return QueueBuilder.durable(QUEUE_EMAIL).build();
    }

    @Bean("QHistory")
    public Queue QHistory(){

        return QueueBuilder.durable(QUEUE_HISTORY).build();
    }

    @Bean("QReaded")
    public Queue QReaded(){

        return QueueBuilder.durable(QUEUE_READED).build();
    }

    @Bean
    public Binding QDiscussAdToEDiscussSearch( @Qualifier("EDiscussSearch") DirectExchange EDiscussSearch ,
                                              @Qualifier("QDiscussAd")Queue QDiscussAd){
        return BindingBuilder.bind(QDiscussAd).to(EDiscussSearch).with("");
    }

    @Bean
    public Binding QDiscussCountToEDisucssComment( @Qualifier("ESearchADD") DirectExchange ESearchADD ,
                                            @Qualifier("QSearch")Queue QSearch){
        return BindingBuilder.bind(QSearch).to(ESearchADD).with("");
    }

}
